home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 351-375 / disk_365 / dmeasm / source / dmeasm.s < prev   
Text File  |  1992-05-06  |  18KB  |  436 lines

  1. *************************************************************************
  2. *  DmeAsm V1.1,  April 1990,  Written by Nic Wilson                     *
  3. *  Based on an original program by Warren Weber                         *
  4. *************************************************************************
  5.  
  6.                 INCDIR  dh0:devpac/include/
  7.                 INCLUDE exec/exec_lib.i
  8.                 INCLUDE intuition/intuitionbase.i
  9.                 INCLUDE intuition/intuition_lib.i
  10.                 INCLUDE libraries/dos_lib.i
  11.  
  12.                         SECTION ,CODE
  13.                 INCLUDE common/macros.i
  14.  
  15.                         SECTION program,DATA
  16.                 INCLUDE dmeasm.data
  17.  
  18.                         SECTION ,CODE
  19.  
  20.                 StartCode
  21. main            bsr     copynames
  22.         moveq   #0,d7
  23.                 lea     patchwindow,a0
  24.                 CALLINT  OpenWindow
  25.                 move.l  d0,ourwindow
  26.                 beq     exit
  27.                 move.l  d0,a0
  28.                 move.l  wd_RPort(a0),rport
  29.                 move.l  wd_UserPort(a0),mport
  30.  
  31.                 move.l  rport,a0
  32.                 lea     IText1,a1
  33.                 moveq   #0,d0
  34.                 moveq   #0,d1
  35.                 CALLINT PrintIText              ;print all our text
  36.  
  37.                 move.l  rport,a0
  38.                 lea     sourceimage,a1          ;source image
  39.                 moveq   #0,d0                   ;leftedge
  40.                 moveq   #0,d1                   ;topedge
  41.                 CALLINT DrawImage
  42.  
  43.                 move.l  _wbmsg,d0               ;are we from WB
  44.                 bne     wbdme                   ;no
  45.  
  46.         ;make 1 of the string gadgets active
  47.  
  48.                 cmpi.l  #0,dmescreen            ;does dmescreen exist
  49.                 bne.s   dmefound                ;yes so make dest gad active
  50.                 lea     sourcestring,a0
  51.                 bsr     activate                ;else, make source gad active
  52.                 bra     checkmsg
  53. dmefound        lea     deststring,a0
  54.                 bsr     activate                ;make destination gadget active
  55.  
  56. ;----------------------------------------------------------
  57. ;       Main Loop, get any messages, check gadgets
  58. ;----------------------------------------------------------
  59.  
  60. checkmsg        move.l  mport,a0
  61.                 CALLEXEC WaitPort
  62.                 move.l  mport,a0
  63.                 CALLEXEC GetMsg
  64.                 move.l  d0,msgpointer           ;save ptr to message struct
  65.                 move.l  d0,a0
  66.                 move.l  im_Class(a0),a1
  67.                 cmpa.l  #GADGETUP,a1
  68.                 beq     checkgadgets
  69.                 move.l  msgpointer,a1
  70.                 bsr     repmessage
  71.                 bra.s   checkmsg
  72.  
  73. ;---------------------------------------------------
  74. ;       Find what gadget was selected
  75. ;---------------------------------------------------
  76.  
  77. checkgadgets    move.l  msgpointer,a1
  78.                 move.l  im_IAddress(a1),a0      ;get address of gadget struct
  79.                 bsr     repmessage
  80.                 move.w  gg_GadgetID(a0),d0
  81.                 cmpi.b  #6,d0                   ;just past toggle select gadgets
  82.                 blt     checkmsg                ;if so skip it
  83.                 cmpi.b  #6,d0                   ;is it cancel
  84.                 beq     cancelhit
  85.                 cmpi.b  #7,d0                   ;is it assemble
  86.                 beq     assemblehit
  87.                 cmpi.b  #8,d0                   ;is it metascope
  88.                 beq     metahit
  89.                 cmpi.b  #9,d0                   ;is it asm/debug
  90.                 beq     asmdebughit
  91.                 cmpi.b  #10,d0                  ;asm/run
  92.                 beq     asmrunhit
  93.                 cmpi.b  #13,d0                  ;run
  94.                 beq     runhit
  95.                 cmpi.b  #11,d0                  ;source
  96.                 beq     sourcehit
  97.                 cmpi.b  #14,d0
  98.                 beq     outhit
  99.                 cmpi.b  #12,d0                  ;destination
  100.                 bne     checkmsg                ;no, loop
  101.  
  102. ;----------------------------------------------------------------------------
  103. ;       Handle the Destination string gadget being edited, assemble being hit
  104. ;----------------------------------------------------------------------------
  105.  
  106. desthit         lea     deststring,a0
  107.                 bsr     stillact
  108.                 lea     outstring,a0
  109.                 bsr     activate
  110.                 bra     checkmsg
  111.  
  112. outhit          lea     outstring,a0
  113.                 bsr     stillact
  114.                 bra     assemblehit
  115.  
  116. stillact        cmpi.w  #SELECTED,gg_Flags(a0)
  117.                 beq     stillact
  118.                 rts
  119.  
  120. assemblehit     bsr     buildcommand            ;build the command line
  121.                 bsr     shutwind                ;close wind
  122.                 move.l  #prog,d1                ;string to loadseg
  123.                 bsr     loadnrun                ;assemble it
  124.                 bra     exit                    ;quit
  125.  
  126. ;---------------------------------
  127. ;       Source gadget routine
  128. ;---------------------------------
  129.         ;copy source to destination string gadget
  130. sourcehit       lea     sourcebuff,a1
  131.                 lea     destbuff,a0
  132.                 bsr     copydest
  133.                 bsr     refreshstrings          ;refresh the string gads
  134.                 lea     deststring,a0
  135.                 bsr     activate                ;activate dest string gad
  136.                 bra     checkmsg
  137.  
  138. ;---------------------------------
  139. ;       Cancel gadget routine
  140. ;---------------------------------
  141.  
  142. cancelhit       bra     closewind               ;exit
  143.  
  144. ;---------------------------------
  145. ;       metascope gadget routine
  146. ;---------------------------------
  147.  
  148. metahit         bsr     shutwind
  149. meta2           lea     destbuff,a1             ;actuall file to metascope
  150.                 lea     metastring,a0           ;execute string
  151.                 adda.l  #11,a0                  ;point to 1st char
  152.                 bsr     copytillnull            ;copy source buff to text string
  153.                 move.l  #metastring,d1          ;metascope text
  154.                 bsr     runit                   ;metascope it
  155.                 bra     exit
  156.  
  157. ;---------------------------------
  158. ;       Run gadget routine
  159. ;---------------------------------
  160.  
  161. runhit          bsr     shutwind
  162.                 lea     runprog,a0              ;destination
  163.                 lea     destbuff,a1             ;source
  164.                 bsr     copytillnull            ;copy to command string
  165.                 move.l  #runprog,d1
  166.                 bsr     runit                   ;run the program
  167.                 bra     exit
  168.  
  169. ;---------------------------------
  170. ;       Asm/Run gadget routine
  171. ;---------------------------------
  172.  
  173. asmrunhit       bsr     buildcommand            ;build the command line
  174.                 bsr     shutwind
  175.                 move.l  #prog,d1                ;string to loadseg
  176.                 bsr     loadnrun                ;assemble it
  177.                 cmpi.l  #4,d0                   ;check return code
  178.                 bge     exit                    ;if 1 or more quit
  179.                 WaitFor 150                     ;allow disk access to stop
  180.  
  181.                 lea     destbuff,a1             ;filename is here
  182.                 lea     runprog,a0              ;program string to run
  183.                 bsr     copytillnull            ;move it in
  184.                 move.l  #runprog,d1             ;run the program
  185.                 bsr     runit
  186.                 bra     exit                    ;quit
  187.  
  188. ;---------------------------------
  189. ;       Asm/Debug gadget routine
  190. ;---------------------------------
  191.  
  192. asmdebughit     bsr     buildcommand
  193.                 bsr     shutwind
  194.                 move.l  #prog,d1                ;string to loadseg
  195.                 bsr     loadnrun                ;assemble it
  196.                 cmpi.l  #4,d0                   ;check return code
  197.                 bge     exit                    ;if 1 or more quit
  198.                 bra     meta2                   ;else metascope it and exit
  199.  
  200. *******************************************************************************
  201. *                               SUBROUTINES
  202. ;-------------------------------------------------------------------
  203. ;       Execute the command string and wait for the task to end.
  204. ;-------------------------------------------------------------------
  205.         ;d1 has string to load
  206.  
  207. loadnrun        move.l   #args,d1
  208.                 moveq    #0,d2
  209.                 moveq    #0,d3
  210.                 CALLDOS  Execute
  211. waittask        move.l   #taskname,a1
  212.                 CALLEXEC FindTask
  213.                 tst.l    d0
  214.                 bne      waittask
  215.                 move.l   d7,d1
  216.                 beq      nowind
  217.                 CALLDOS  Close
  218. nowind          rts
  219.  
  220. ;---------------------------------------------------------------
  221. ;       Find which gadgets are selected, build the command line
  222. ;---------------------------------------------------------------
  223.  
  224. buildcommand    lea     outbuff,a0
  225.                 cmpi.b  #0,(a0)
  226.                 beq     opencon
  227.                 move.l  #smallwind,d1
  228.                 move.l  #MODE_NEWFILE,d2
  229.                 CALLDOS Open
  230.                 move.l  d0,d7
  231.                 lea     prog1,a0
  232.                 lea     outbuff,a1
  233.                 bsr     copytillnull
  234.                 subq.l  #1,a0
  235.                 move.b  #$20,(a0)+
  236.                 move.b  #0,(a0)
  237. opencon         lea     prog,a1
  238.                 lea     args,a0                 ;command to loadseg
  239.                 bsr     copytillnull
  240.                 subq.l  #1,a0
  241. fillrest        lea     sourcebuff,a1           ;source
  242.                 bsr     copytillnull            ;copy source name to command line
  243.                 move.b  #' ',-1(a0)             ;insert a space
  244.                 move.b  #'-',(a0)+
  245.                 lea     gadgetlist,a2
  246.                 move.w  gg_Flags(a2),d0         ;debug gadget
  247.                 btst.l  #7,d0                   ;is it selected
  248.                 bne     .link                   ;yes(no debug wanted)
  249.                 move.b  #'d',(a0)+              ;d for debug
  250.  
  251. .link           lea     linkgad,a2
  252.                 move.w  gg_Flags(a2),d0         ;link gadget
  253.                 btst.l  #7,d0                   ;is it selected
  254.                 beq     .slowmem                ;no
  255.                 move.b  #'l',(a0)+              ;l for link
  256.  
  257. .slowmem        lea     memgad,a2
  258.                 move.w  gg_Flags(a2),d0         ;slow assemble memory
  259.                 btst.l  #7,d0                   ;is it selected
  260.                 beq     .insertdest             ;no
  261.                 move.b  #'m',(a0)+              ;m slow assemble
  262.  
  263. .insertdest     move.b  #'o',(a0)+              ;insert the needed o
  264.                 lea     destbuff,a1             ;source for copy a0 has dest
  265.                 bsr     copytillnull            ;insert it
  266.  
  267. .list           lea     listgad,a2              ;listing gadget
  268.                 move.w  gg_Flags(a2),d0
  269.                 btst.l  #7,d0                   ;is it selected
  270.                 beq     .nolist                 ;finished
  271.                 move.b  #' ',-1(a0)             ;insert a space
  272.                 move.b  #'-',(a0)+              ;insert the -
  273.                 move.b  #'p',(a0)+              ;p for listing file
  274.                 lea     destbuff,a1             ;list file name
  275.                 bsr     copytillnull
  276.                 move.b  #'.',-1(a0)             ;build .lst extension
  277.                 move.b  #'l',(a0)+
  278.                 move.b  #'s',(a0)+
  279.                 move.b  #'t',(a0)+
  280.                 move.b  #0,(a0)                 ;null command line
  281. .nolist         rts
  282.  
  283. ;------------------------------------------------------------------
  284. ;       copy filename from CLI paramter to string buffer
  285. ;------------------------------------------------------------------
  286.  
  287. copynames    move.l   _argv,a1        ;get param array
  288.         move.l   (a1),a1        ;get first param
  289.             lea     sourcebuff,a0           ;source string gadget
  290. .move           move.b  (a1)+,(a0)+             
  291.                 cmpi.b  #$0,(a1)
  292.                 bne     .move
  293. .done           move.b  #0,(a0)
  294.  
  295.         ;copy from source string buffer to destination string buffer
  296.         
  297. copydest        lea     sourcebuff,a1           ;source buffer
  298.                 lea     destbuff,a0             ;destination buffer
  299.                 moveq   #1,d0                   ;set for one char
  300. .copy           addq.b  #1,d0                   ;increment character count
  301.                 move.b  (a1)+,(a0)+             ;move source to dest
  302.                 bne     .copy                   ;stop on zero
  303.                 subq.b  #2,d0                   ;correct for dbf
  304. .dot            cmpi.b  #'.',-(a0)              ;find dot
  305.                 beq     .null                   ;found dot
  306.                 dbf     d0,.dot
  307.                 bra     .done
  308. .null           move.b  #0,(a0)+                ;clear dot
  309. .done           lea     destbuff,a0
  310.                 CountString
  311.                 lea     deststringSInfo,a0      ;string info struct
  312.                 move.w  d0,si_BufferPos(a0)     ;cursor pos in string gadget
  313.                 rts
  314.  
  315. ;----------------------
  316. ;reply to all mesages
  317. ;----------------------
  318.  
  319. repmessage      pushscr
  320.                 move.l  a1,d0
  321.                 beq     .nomsg
  322.                 CALLEXEC ReplyMsg
  323. .nomsg          popscr
  324.                 rts
  325.  
  326. ;-----------------------------------
  327. ;       Execute their command line
  328. ;-----------------------------------
  329.  
  330.         ;command to execute must be in d1
  331. runit           move.l  d1,a0                   ;string to execute
  332.                 tst.b   (a0)                    ;is there anything to execute
  333.                 beq     no                     ;no
  334.                 moveq   #0,d2                   ;input
  335.                 move.l  _stdout,d3
  336.                 CALLDOS Execute
  337.                 ActWindow               ;activate cli window
  338. no             rts
  339.  
  340. ;----------------------------------
  341. ;       Copy Memory Routine
  342. ;----------------------------------
  343.         ;copy memory untill a null is found, a1 source a0 dest
  344. copytillnull    move.b  (a1)+,(a0)+
  345.                 bne     copytillnull            ;continue till null found
  346.                 move.b  #0,(a0)                 ;null it
  347.                 rts
  348.  
  349. ;------------------------------
  350. ;       Refresh string gadgets
  351. ;------------------------------
  352.  
  353. refreshstrings  lea     sourcestring,a0         ;start at source string gad
  354.                 move.l  ourwindow,a1
  355.                 move.l  #0,a2                   ;no requestors
  356.                 CALLINT RefreshGadgets
  357.                 rts
  358.  
  359. ;------------------------------------------------------
  360. ;       activate a string gadget, gadget must be in a0
  361. ;------------------------------------------------------
  362.  
  363. activate        move.l  ourwindow,a1
  364.                 suba.l  a2,a2                   ;no requestors
  365.                 CALLINT ActivateGadget
  366.                 rts
  367.  
  368. ;--------------------------
  369. ;       Close our window
  370. ;--------------------------
  371.  
  372. shutwind        move.l  ourwindow,a0
  373.                 CALLINT CloseWindow
  374.                 rts
  375.  
  376. *****************************************************************************
  377. *                       ERROR ROUTINES
  378.  
  379.         ;-----------------------------------------------
  380.         ;       Warn if we cant do a loadseg on Genim2
  381.         ;-----------------------------------------------
  382. errloadseg      lea     loadsegmsg,a0           ;print error msg
  383.                 move.l  _stdout,d1
  384.                 DosPrint
  385.                 addq.l  #4,a7                   ;replace the rts and exit
  386.                 bra     exit
  387.  
  388.         ;-------------------------------------------------
  389.         ;       Warn that this program runs from cli only
  390.         ;-------------------------------------------------
  391. wbdme           move.l  rport,a0
  392.                 lea     statusstruct,a1
  393.                 move.l  #wbdmemsg,it_IText(a1)  ;print an error msg
  394.                 moveq   #0,d0                   ;x
  395.                 moveq   #0,d1                   ;y
  396.                 CALLINT PrintIText
  397.                 WaitFor 350
  398.  
  399. *****************************************************************************
  400. *                               EXIT
  401.  
  402. closewind       bsr     shutwind
  403. exit            ActWindow
  404.                 rts
  405.  
  406. *****************************************************************************
  407. *                               DATA
  408.  
  409.                         SECTION program,DATA
  410. smallwind       dc.b    'con:0/0/200/10/Assembling... ',0
  411. prog            dc.b    'sys:c/GenIm2 >'
  412. prog1           dc.b    'con:0/0/640/255/Assembling... ',0
  413. args            dc.b    '                                                                                         ',0
  414. metastring      dc.b    'MetaScope                                         ',0
  415. wbdmemsg        dc.b    'DmeAsm runs from Cli only',0
  416. runprog         dc.b    '                                      ',0
  417. loadsegmsg      dc.b    114,$0a,' Cant run Genim2, check that its in the C or current directory',$0a
  418.                 dc.b    '       and that there is enough memory to run it.',$0a,0
  419. taskname        dc.b    'GenIm2',0
  420. *****************************************************************************
  421.  
  422.                         SECTION variables,BSS
  423.         cnop 0,4
  424. rport           ds.l    1
  425. mport           ds.l    1
  426. dmescreen       ds.l    1
  427. ourwindow       ds.l    1
  428. msgpointer      ds.l    1
  429. segment         ds.l    1
  430. flag            ds.b    1
  431. sourcebuff      ds.b    40
  432. destbuff        ds.b    40
  433. outbuff         ds.b    40
  434.  
  435.         END
  436.